var t = require("../../../@babel/runtime/helpers/defineProperty"), i = getApp();

Page({
    data: {
        id: "",
        currentTime: parseInt(new Date().getTime() / 1e3),
        timeData: {},
        checked: !1,
        multiplePopupInfo: {
            title: "",
            info: {},
            show: !1
        },
        goodsDetailsPopupInfo: {
            show: !1,
            info: {}
        },
        singlePopupInfo: {
            title: "",
            show: !1,
            info: {}
        },
        posterPopupInfo: {
            show: !1,
            src: ""
        },
        contactShow: !1,
        friendsShow: !1,
        seePrizeShow: !1,
        seePrizeAnimation: !1,
        gifShow: !1,
        goods: [],
        activity: {},
        assist: {},
        member: {},
        timer: null,
        luckdrawCountDown: 0,
        isBlindBoxTap: !0,
        isBlindBoxTapPay: !1,
        isInvitePlan: !1,
        isAddress: !1,
        integral: "积分"
    },
    onLoad: function(t) {
        if (console.log(t), t.scene) {
            var a = decodeURIComponent(t.scene);
            if (a) {
                var o = [];
                o = a.split(",");
                for (var e = 0; e < o.length; e++) {
                    var s;
                    "mid" == (s = o[e].split("="))[0] && i._setMid(s[1]), "id" == s[0] && this.setData({
                        id: s[1]
                    });
                }
            }
        }
        t.ids && this.getBlindBoxGoods(t.ids), t.id && this.setData({
            id: t.id
        });
        var n = wx.getStorageSync("integral");
        n && this.setData({
            integral: n
        });
    },
    onChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    onReady: function() {},
    previewImage: function(t) {
        console.log("浏览图片");
        var i = this.data.activity.cservice_code_src;
        wx.previewImage({
            current: i,
            urls: [ i ]
        });
    },
    previewImagesss: function() {
        var t = this.data.posterPopupInfo.src;
        wx.previewImage({
            current: t,
            urls: [ t ]
        });
    },
    onShow: function() {
        this.animation = wx.createAnimation({
            duration: 3e3,
            timingFunction: "ease"
        }), console.log(this.data.timer), this.data.id && (this.data.timer && clearInterval(this.data.timer), 
        this.getData());
    },
    onHide: function() {
        console.log("asdasdasdassdadasd"), clearInterval(this.data.timer);
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = "/packageH/blindBox/blindBoxHelping/blindBoxHelping?assist_id=" + this.data.assist.id + "&member_id=" + this.data.assist.member_id, i = "packageH/blindBox/blindBoxDetail/blindBoxDetail?id=" + this.data.id;
        return {
            title: this.data.activity.activity_name ? this.data.activity.activity_name : "",
            path: this.data.activity.activity_type ? t : i,
            imageUrl: this.data.activity.activity_img_src ? this.data.activity.activity_img_src : ""
        };
    },
    callPhone: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.activity.cservice_phone
        });
    },
    goOrder: function() {
        wx.navigateTo({
            url: "/packageA/member/myOrder_v2/myOrder_v2?status=0"
        });
    },
    contactShowTap: function() {
        this.setData({
            contactShow: !0
        });
    },
    contactShowClose: function() {
        this.setData({
            contactShow: !1
        });
    },
    getData: function() {
        var a = this, o = this, e = i.getNetAddresss("plugin.blind-box.api.index.activity-info");
        i._postNetWork({
            url: e,
            data: {
                id: this.data.id
            },
            success: function(i) {
                var e = i.data;
                if (wx.hideLoading({
                    success: function(t) {}
                }), 1 == e.result) {
                    o.setData({
                        goods: e.data.goods,
                        activity: e.data.activity,
                        assist: e.data.assist,
                        member: e.data.member
                    });
                    var s = o.data.activity.activity_rule.replace(/<img/g, '<img style="width:100%"');
                    if (o.setData(t({}, "activity.activity_rule", s)), o.data.assist && o.data.assist.expire && (console.log("currentTime", o.data.currentTime, o.data.assist.expire), 
                    o.data.currentTime <= o.data.assist.expire || 1 == o.data.assist.status)) return void o.setData({
                        isBlindBoxTap: !1,
                        isInvitePlan: !0
                    });
                    o.setData({
                        luckdrawCountDown: o.data.activity.extract_time
                    }), a.startLuckCountDown();
                } else console.log(e);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    startLuckCountDown: function() {
        var t = this;
        t.data.timer = setInterval(function() {
            t.data.luckdrawCountDown <= 0 ? clearInterval(t.data.timer) : t.setData({
                luckdrawCountDown: t.data.luckdrawCountDown - 1
            });
        }, 1e3);
    },
    freePrize: function() {
        var t = this;
        setTimeout(function() {
            t.setData({
                seePrizeAnimation: !0
            }), setTimeout(function() {
                t.setData({
                    gifShow: !1
                });
            }, 500);
        }, 1500), t.setData({
            gifShow: !0,
            seePrizeShow: !0,
            isAddress: !0
        });
    },
    startLuckDraw: function() {
        var t = this;
        t.data.luckdrawCountDown <= 0 ? wx.showToast({
            title: "请刷新或重新进入",
            duration: 1e3,
            icon: "none"
        }) : (t.addJoinLog(), 0 == t.data.activity.activity_type ? (setTimeout(function() {
            t.setData({
                seePrizeAnimation: !0
            }), setTimeout(function() {
                t.setData({
                    gifShow: !1
                });
            }, 500);
        }, 1500), t.setData({
            gifShow: !0,
            isBlindBoxTapPay: !0,
            seePrizeShow: !0
        })) : 1 == t.data.activity.activity_type && this.generateAssist());
    },
    addJoinLog: function() {
        var t = i.getNetAddresss("plugin.blind-box.api.index.join-log");
        i._postNetWork({
            url: t,
            data: {
                id: this.data.activity.id
            },
            success: function(t) {},
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    generateAssist: function() {
        var a = this, o = i.getNetAddresss("plugin.blind-box.api.assist.generate-assist");
        i._postNetWork({
            url: o,
            data: {
                id: a.data.id
            },
            success: function(i) {
                var o, e = i.data;
                1 == e.result ? a.setData((o = {
                    isBlindBoxTap: !1,
                    isInvitePlan: !0,
                    assist: e.data.assist
                }, t(o, "assist.assist_log_count", e.data.assist.assist_log.length), t(o, "assist.status", 0), 
                o)) : console.log(e);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    seePrizeShowTap: function() {
        wx.redirectTo({
            url: "/packageH/blindBox/blindBoxDetail/blindBoxDetail?id=" + this.data.id
        });
    },
    onceMore: function(t) {
        wx.redirectTo({
            url: "/packageH/blindBox/blindBoxDetail/blindBoxDetail?id=" + this.data.id
        });
    },
    openGoodsDetailsPopup: function(i) {
        var a;
        console.log(i);
        var o = i.currentTarget.dataset.item;
        this.setData((t(a = {}, "goodsDetailsPopupInfo.info", o), t(a, "goodsDetailsPopupInfo.show", !0), 
        a)), console.log(this.data.goodsDetailsPopupInfo);
    },
    seeCombinationGoods: function(i) {
        var a, o = i.currentTarget.dataset.item;
        this.setData((t(a = {}, "multiplePopupInfo.info", o.combination), t(a, "multiplePopupInfo.title", o.combination.combination_name), 
        t(a, "multiplePopupInfo.show", !0), a));
    },
    multiplePopupInfoTap: function() {
        this.setData(t({}, "multiplePopupInfo.show", !1));
    },
    singlePopupInfoTap: function() {
        this.setData(t({}, "singlePopupInfo.show", !1));
    },
    seeTips: function() {
        var t = this;
        this.data.activity.tips - this.data.activity.tips_count <= 0 ? wx.showModal({
            title: "提示一次需要消耗".concat(t.data.activity.tips_consume).concat(t.data.integral),
            content: "当前".concat(t.data.integral).concat(this.data.member.credit1),
            success: function(i) {
                i.confirm && (console.log("用户点击确定"), t.getTips());
            }
        }) : this.getTips();
    },
    getTips: function() {
        var a = this, o = this, e = i.getNetAddresss("plugin.blind-box.api.tips.get-tips");
        i._postNetWork({
            url: e,
            data: {
                id: o.data.id
            },
            success: function(i) {
                var e, s = i.data;
                1 == s.result ? (o.setData((t(e = {}, "activity.tips_count", a.data.activity.tips_count + 1), 
                t(e, "singlePopupInfo.title", "不可能抽中"), t(e, "singlePopupInfo.info", s.data.activityGoods), 
                t(e, "singlePopupInfo.show", !0), e)), console.log(a.data.singlePopupInfo)) : (wx.showToast({
                    title: s.msg,
                    duration: 1e3,
                    icon: "none"
                }), console.log(s));
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    gotoOrder: function(t) {
        console.log(t), wx.navigateTo({
            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=blindBox&goodsId=" + this.data.activity.goods_id + "&at_id=" + this.data.activity.id + "&total=1&optionsId="
        });
    },
    getBlindBoxGoods: function(a) {
        var o = this, e = i.getNetAddresss("plugin.blind-box.api.index.blind-box-goods");
        i._postNetWork({
            url: e,
            data: {
                order_id: a
            },
            success: function(i) {
                var a = i.data;
                if (wx.hideLoading({
                    success: function(t) {}
                }), 1 == a.result) {
                    var e, s;
                    if (null == a.data.combination) o.setData(t({}, "blindBoxInfo.pattern", 0)); else o.setData((t(s = {}, "blindBoxInfo.pattern", 1), 
                    t(s, "blindBoxInfo.combination", a.data.combination), s));
                    o.setData((t(e = {}, "blindBoxInfo.show", !0), t(e, "blindBoxInfo.goods", a.data.goods), 
                    e));
                } else console.log(a);
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getPoster: function(a) {
        if ("" == this.data.posterPopupInfo.src) {
            var o = this, e = i.getNetAddresss("plugin.blind-box.api.index.poster");
            i._postNetWork({
                url: e,
                data: {
                    activity_id: o.data.id,
                    ingress: "weChatApplet"
                },
                success: function(i) {
                    var a, e = i.data;
                    (wx.hideLoading({
                        success: function(t) {}
                    }), 1 == e.result) ? o.setData((t(a = {}, "posterPopupInfo.src", e.data.poster), 
                    t(a, "posterPopupInfo.show", !0), a)) : (console.log(e), wx.showToast({
                        title: e.meg,
                        duration: 1e3,
                        icon: "none"
                    }));
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        } else this.setData(t({}, "posterPopupInfo.show", !0));
    },
    posterPopupInfoClose: function() {
        this.setData(t({}, "posterPopupInfo.show", !1));
    }
});